package com.edu.www;


import javax.print.attribute.standard.MediaName;

import org.checkerframework.dataflow.qual.TerminatesExecution;
import org.junit.experimental.theories.Theories;
import org.testng.annotations.Test;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;


public class Xuanxuan extends BaseDriver{
	public static void main(String[] args) {
		
	}
	
	//向系统发送信息
	@Test
	public void test1() throws InterruptedException {
		driver.findElement(AppiumBy.accessibilityId("系统")).click();
		Thread.sleep(2000);
		driver.pressKey(new KeyEvent(AndroidKey.L));
		driver.pressKey(new KeyEvent(AndroidKey.H));
		driver.pressKey(new KeyEvent(AndroidKey.Z));
		driver.findElement(AppiumBy.xpath("//*[@text='发送消息']")).sendKeys("向系统发送信息");
		Thread.sleep(2000);
		driver.findElement(AppiumBy.accessibilityId("发送")).click();
		Thread.sleep(2000);
	}
	
	//向admin发送图片
	@Test
	public void test2() throws InterruptedException {
		driver.findElement(AppiumBy.accessibilityId("A admin（我） 4月26日 hh")).click();
		Thread.sleep(2000);
		driver.findElement(AppiumBy.accessibilityId("发送其他内容")).click();
		Thread.sleep(2000);
		driver.findElement(AppiumBy.accessibilityId("照片")).click();
		Thread.sleep(2000);
		driver.findElement(AppiumBy.xpath("//*[@text='图片']")).click();
		Thread.sleep(2000);
		driver.findElement(AppiumBy.xpath("//*[@text='图片']")).click();
		Thread.sleep(2000);
		driver.findElement(AppiumBy.id("android:id/action_bar_title")).click();
		Thread.sleep(2000);
		driver.findElement(AppiumBy.className("android.widget.ImageView")).click();
	}

	
	//查看相关信息
	@Test
	public void test3() throws InterruptedException {
			driver.findElement(AppiumBy.accessibilityId("显示菜单")).click();
			Thread.sleep(2000);
			driver.findElement(AppiumBy.accessibilityId("关于")).click();
			Thread.sleep(2000);
			driver.findElement(AppiumBy.accessibilityId("关闭")).click();
			Thread.sleep(2000);
	}
	
	//向小暄暄循环发送10条消息
	@Test
	public void test4() throws InterruptedException {
		for(int i=1; i<=10; i++) {
//			driver.findElement(AppiumBy.accessibilityId("群 小喧喧")).click();
			driver.findElement(AppiumBy.xpath("//android.view.View[@content-desc=\"群 小喧喧\"]")).click();
			Thread.sleep(2000);
			driver.findElement(AppiumBy.xpath("//*[@text='发送消息']")).sendKeys("向admin发送第" + i +"信息");
			Thread.sleep(2000);
			driver.findElement(AppiumBy.accessibilityId("发送")).click();
			Thread.sleep(2000);
		}
	}
	
	//找到讨论组
	@Test
	public void test5() throws InterruptedException {
		driver.findElement(AppiumBy.accessibilityId("A admin（我） 4月26日 hh")).click();
		Thread.sleep(2000);
		driver.findElement(AppiumBy.accessibilityId("返回")).click();
		Thread.sleep(2000);
		driver.findElement(AppiumBy.accessibilityId("讨论组")).click();
		Thread.sleep(2000);

	}

	
	//通过通讯录找到成员djw并发送信息
	@Test
	public void test6() throws InterruptedException {
		driver.findElement(AppiumBy.accessibilityId("通讯录\\n通讯录\\n第 2 个标签，共 3 个")).click();
		Thread.sleep(2000);
		driver.findElement(AppiumBy.accessibilityId("D\ndjw")).click();
		Thread.sleep(2000);
		driver.findElement(AppiumBy.accessibilityId("开聊")).click();
		Thread.sleep(2000);
		driver.findElement(AppiumBy.xpath("//*[@text='发送消息']")).sendKeys("向djw发送信息");
	}
	
}
